package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28779
 * Date: 2023-04-01
 * Time: 9:42
 */
public class BorrowOperation implements IOPeration{
    @Override
    public void work(BookList bookList) {
        int currentSize = bookList.getUseSize();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要借出的书名:>");
        String name = scanner.nextLine();

        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)){
                if(book.isBorrowed() == true){
                    System.out.println("此书已被借出！！！");
                    return;
                }
                book.setBorrowed(true);
                System.out.println(book);
                System.out.println("成功借出！！！");
            }
        }
        //System.out.println("借阅图书！！");
    }
}
